class NoticesController < ApplicationController

  sidebar :deposits, :if => :logged_in?
  sidebar :ajax_module_balans, :if => :logged_in?
  
  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }
  
  def index
    list
    render :action => 'list'
  end
  
  def list
    @notices = Notice.find(:all)
  end
  
  def save
    @notice = Notice.find_by_id(params[:id]) || Notice.new(params[:notice])
    
    if @notice.new_record?
      @notice.created_by = current_user.id
    end
    
    if @notice.save
      flash[:message] = 'De post-it is opgeslagen.'
    else
      flash[:error] = 'Er ging iets mis bij het opslaan van de post-it'
    end
    
    redirect_to :controller => 'notices', :action => 'list'
  end
  
end